package ca.uwo.android.campusmap;

import java.util.ArrayList;

import android.graphics.drawable.Drawable;
import android.os.Handler;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class CampusMapOverlay extends ItemizedOverlay<OverlayItem> {
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	final Handler dataHandler;
	
	public CampusMapOverlay(Drawable defaultMarker, Handler h) {
		super(boundCenter(defaultMarker));
		dataHandler = h;
	}

	public void addOverlays(OverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}

	public void clear() {
		mOverlays.clear();
		populate();
	}
	
	@Override
	public boolean onTap(int index) {
		dataHandler.sendEmptyMessage(index);
		return true;
	}
}
